import pandas as pd

from tools import *

pd.set_option('display.unicode.east_asian_width', True)

def get_上机_签到(上机='上机1') -> DataFrame:
    file_path = f"{BASE_PATH_5G实训}/课后统计/{上机}签到.xlsx"
    df_result = pd.read_excel(file_path)
    return df_result


def concat_上机_签到(output_path=None):
    df_学生_信息 = get_学生_信息()

    df_上机1_签到 = get_上机_签到('上机1')
    df_上机2_签到 = get_上机_签到('上机2')
    df_上机3_签到 = get_上机_签到('上机3')
    df_上机4_签到 = get_上机_签到('上机4')
    df_上机5_签到 = get_上机_签到('上机5')
    df_上机6_签到 = get_上机_签到('上机6')
    df_上机7_签到 = get_上机_签到('上机7')
    df_上机8_签到 = get_上机_签到('上机8')

    df_上机1_签到.rename(columns={'状态': '上机1'}, inplace=True)
    df_上机2_签到.rename(columns={'状态': '上机2'}, inplace=True)
    df_上机3_签到.rename(columns={'状态': '上机3'}, inplace=True)
    df_上机4_签到.rename(columns={'状态': '上机4'}, inplace=True)
    df_上机5_签到.rename(columns={'状态': '上机5'}, inplace=True)
    df_上机6_签到.rename(columns={'状态': '上机6'}, inplace=True)
    df_上机7_签到.rename(columns={'状态': '上机7'}, inplace=True)
    df_上机8_签到.rename(columns={'状态': '上机8'}, inplace=True)

    df_merged = merge_student_dataframes(df_学生_信息, df_上机1_签到, df_上机2_签到, df_上机3_签到, df_上机4_签到,
                                         df_上机5_签到, df_上机6_签到, df_上机7_签到, df_上机8_签到)

    # 如果需要，保存到Excel
    if output_path:
        df_merged.to_excel(output_path, index=False)
        print(f"\n✅ 所有出勤合并完成! 文件已保存至: {output_path}")
    return df_merged

if __name__ == "__main__":
    path = f"{BASE_PATH_5G实训}\课后统计\上机签到_汇总.xlsx"
    concat_上机_签到(path)
